/**
@file     	DESIGNPATTERN_Directory.cpp
@brief    	1.When the algorithm to create complex object should be independent of the part of the object,
as well as their assembly;
2.When construction process must be allowed to construct the object is different;
@author  	arvin
@version 	1.0   2012/12/20
*/

#include "stdafx.h"

#ifndef CXX_DESIGNPATTERN_DIRECTORY_H
#include "DESIGNPATTERN_Directory.h"
#endif

/**
* Construction
*
* @param const string& strName
* @param int iSize
* @return
*/
Directory::Directory(const string& strName, int iSize) :
	Entry(ENTRY_DIRECTORY, strName, iSize)
{
	DEBUG_PRINTF("");
}

/**
* Destruction
*
* @param VOID
* @return
*/
Directory::~Directory()
{
	DEBUG_PRINTF("");
	list<Entry*>::iterator iter;
	for (iter = m_listEntry.begin(); iter != m_listEntry.end(); iter++) {
		if (NULL != (*iter)) {
			delete (*iter);
			(*iter) = NULL;
		}
	}
}

/**
* PrintList
*
* @param VOID
* @return VOID
*/
VOID 
Directory::PrintList()
{
	DEBUG_PRINTF("name[%s], size[%d]", GetName().c_str(), GetSize());
	Entry::PrintList();

	list<Entry*>::iterator iter;
	for (iter = m_listEntry.begin(); iter != m_listEntry.end(); iter++) {
		(*iter)->PrintList();
	}
}

/**
* GetSize
*
* @param VOID
* @return int
*/
int 
Directory::GetSize()
{
	DEBUG_PRINTF("");
	Entry::GetSize();
	int iSize = 0;
	list<Entry*>::iterator iter;
	for (iter = m_listEntry.begin(); iter != m_listEntry.end(); iter++)	{
		iSize += (*iter)->GetSize();
	}
	return iSize;
}

/**
* Add
*
* @param Entry* pEntry
* @return bool
*/
bool
Directory::Add(Entry* pEntry)
{
	DEBUG_PRINTF("");
	m_listEntry.push_back(pEntry);
	return true;
}

/**
* Remove
*
* @param Entry* pEntry
* @return bool
*/
bool
Directory::Remove(Entry* pEntry)
{
	DEBUG_PRINTF("");
	m_listEntry.remove(pEntry);
	return true;
}

/**
* GetChild
*
* @param VOID
* @return list<Entry*>
*/
list<Entry*>
Directory::GetChild()
{
	DEBUG_PRINTF("");
	return m_listEntry;
}

/* EOF */